package com.example.yiqiuser.service.impl;

import com.example.yiqiuser.dao.SeasonDao;
import com.example.yiqiuser.entity.Season;
import com.example.yiqiuser.service.SeasonService;
import com.example.yiqiuser.util.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: yiqiuser
 * @description:
 * @author: 诸葛龙辰
 * @create: 2023-03-31 09:33
 * @version:
 **/
@Service
public class SeasonServiceImpl implements SeasonService {
    @Resource//依赖注入
    private SeasonDao seasonDao;

    /**
     * 分页查询
     * @param page
     * @return
     */
    @Override
    public PageInfo queryPage(Page<Season> page) {
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        return new PageInfo(seasonDao.queryByParam(page.getData()));
    }

    /**
     * 查询所有时令
     * @return
     */
    @Override
    public List<Season> queryAll() {
        return seasonDao.queryAll();
    }

    /**
     * 根据时令id查询
     * @param code
     * @return
     */
    @Override
    public Season queryById(Integer code) {
        List<Season> seasonsList = seasonDao.queryById(code);
        if (seasonsList!=null&&seasonsList.size()>0){
            return seasonsList.get(0);
        }
        return null;
    }

    /**
     * 添加
     * @param season
     * @return
     */
    @Override
    public int add(Season season) {
        return seasonDao.add(season);
    }

    /**
     * 更改
     * @param season
     * @return
     */
    @Override
    public int update(Season season) {
        return seasonDao.update(season);
    }

    /**
     * 根据id删除
     * @param code
     * @return
     */
    @Override
    public int deleteById(Integer code) {
        return seasonDao.deleteById(code);
    }
}
